package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.NoteUpdateDto;
import com.tianji.learning.domain.dto.NotesDto;
import com.tianji.learning.domain.query.NotesQuery;
import com.tianji.learning.domain.vo.NotesPageVo;
import com.tianji.learning.service.INoesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xzh
 * @since 2024-03-27
 */
@RestController
@RequestMapping("/notes")
@Api(tags = "学习笔记相关接口")
@RequiredArgsConstructor
public class NoesController {
    private final INoesService noesService;

    /**
     * 保存学习笔记
     */
    @PostMapping
    @ApiOperation(value = "保存学习笔记")
    public void saveNote(@RequestBody @Valid NotesDto dto){
        noesService.saveNote(dto);
    }

    /**
     * 采集笔记
     * @param id
     */
    @PostMapping("/gathers/{id}")
    @ApiOperation(value = "采集笔记")
    public void saveGatheredNoteById(@PathVariable("id") Long id){
        noesService.saveGatheredNoteById(id);
    }

    /**
     * 取消采集笔记
     * @param id
     */
    @DeleteMapping("/gathers/{id}")
    @ApiOperation(value = "取消采集笔记")
    public void removeGatheredNoteById(@PathVariable("id") Long id){
        noesService.removeGatheredNoteById(id);
    }

    /**
     * 编辑笔记
     * @param id
     * @param dto
     */
    @PutMapping("/{id}")
    @ApiOperation(value = "编辑笔记")
    public void updateNoteById(@PathVariable("id") Long id, @RequestBody @Valid NoteUpdateDto dto){
        noesService.updateNoteById(id, dto);
    }

    /**
     * 删除笔记
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除笔记")
    public void removeNoteById(@PathVariable("id") Long id){
        noesService.removeNoteById(id);
    }

    /**
     * 笔记分页查询
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "笔记分页查询")
    public PageDTO<NotesPageVo> queryNotesPage(NotesQuery query){
        return noesService.queryNotesPage(query);
    }
}
